import { Controller, Post, Body, Get } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Code, Repository } from 'typeorm';
import { MetalDataDto } from '../common/dtos/metal-data.dto';
import { MetalDataEntity } from '../common/entities/metal-data.entity';

@Controller('changjiang-youse')
export class ChangjiangYouseController {
  constructor(
    @InjectRepository(MetalDataEntity)
    private readonly metalDataRepository: Repository<MetalDataEntity>,
  ) {}

  @Post()
  async addData(@Body() metalData: MetalDataDto) {
    const newData = this.metalDataRepository.create(metalData);
    await this.metalDataRepository.save(newData);
    return { code:"201", message: 'Data added successfully', data: newData };
  }
  @Get()
  async getAllData() {
    const data = await this.metalDataRepository.find();
    return { code: "200", message: 'Data retrieved successfully', data: data };
  }
}